package com.yhy.tradesystem.techdata;

import java.util.ArrayList;

public class MATechDataFilter implements TechDataFilter {
	private ArrayList<Float> techData;
	private int days;
	public MATechDataFilter(int days){
		this.days = days;
	}
	/* (non-Javadoc)
	 * @see com.yhy.stockchart.TechDataFilter#genData(int)
	 */
	@Override
	public Float getData(int index){
		return techData.get(index);
	}
	/* (non-Javadoc)
	 * @see com.yhy.stockchart.TechDataFilter#genData(java.util.ArrayList)
	 */
	@Override
	public ArrayList<Float>  genData(ArrayList<Float> data){
		techData = new ArrayList<Float>();
		if(data.size() > days){
			for(int index=0;index<data.size();index++){
				if(index<(days-1)){
					techData.add(data.get(0));
				}else{
					float total=0.0f;
					for(int j=0;j<days;j++){
						total+=data.get(index-j);
					}
					techData.add(total/(float)days);
				}
			}
		}
		return techData;
	}
	@Override
	public String getName() {
		return days+"日移动平均线";
	}
}
